package com.itheima.controller;

import com.itheima.bean.Course;
import com.itheima.result.Result;
import com.itheima.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/courses")
public class CourseController {

    @Autowired
    private CourseService courseService;
    //TODO: 完成查询学科功能

    /**
     * 查询学科
     * @return
     */
    @GetMapping
    public Result<List<Course>> getCourseInfo() {
        log.info("查询学科");
        List<Course> courseList = courseService.getCourseInfo();
        return Result.success(courseList);
    }


    //TODO: 完成添加学科功能

    /**
     * 添加学科
     * @param course
     * @return
     */
    @PostMapping
    public Result addCourse(@RequestBody Course course) {
        log.info("添加学科 {}",course);
        courseService.addCourse(course);

        return Result.success();
    }
}
